package com.spring.student.systemDB.dao;

import com.spring.student.systemDB.bean.Scores;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.swing.*;
import java.util.List;
@Repository
public class SconresDaoIpml implements ISconresDao{
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Override
    public List<Scores> selectAll() {
        String sql = "select * from scores";
        List<Scores> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Scores>(Scores.class));
        return query;
    }

    @Override
    public Scores getScores(String number) {
        String sql = "select * from scores where number = ?";
        Scores Scores = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<Scores>(Scores.class), number);
        return Scores;
    }

    @Override
    public int insertScores(Spring newnumber, Spring newChinese, Spring newEnglish, Spring newmath) {
        String sql = "insert into scores(number,chinese,english,math) values(?,?,?,?)";
        int update = jdbcTemplate.update(sql, new Object[]{newnumber, newChinese, newEnglish, newmath});
        return update;
    }

    @Override
    public int updateScores(Integer newmath, String number) {
        String sql = "update scores set math = ? where number = ?";
        int update = jdbcTemplate.update(sql, new Object[]{newmath, number});
        return update;
    }
}
